package com.hxc.shop.controller;

import com.hxc.shop.bean.ShopGoodsOrder;
import com.hxc.shop.common.ResultVO;
import com.hxc.shop.service.GoodsOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/goodsOrder")
@CrossOrigin
@Api(tags = {"商品订单数据处理"})
public class GoodsOrderController {
    @Resource
    private GoodsOrderService orderService;

    @ApiOperation("新增订单")
    @PostMapping("/addGoodsOrder")
    @Transactional(rollbackFor = Exception.class)
    public ResultVO addGoodsOrder(@RequestBody ShopGoodsOrder order){
        return orderService.addGoodsOrder(order);
    }

    @ApiOperation("获取所有订单")
    @GetMapping("/getAllGoodsOrder")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value="用户名",required = true,paramType = "String")
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO getAllGoodsOrder(@RequestParam("userName")String userName){
        return orderService.getAllGoodsOrder(userName);
    }

    @ApiOperation("根据订单状态获取信息订单")
    @GetMapping("/getGoodsOrderByStatus")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value="用户名",required = true,paramType = "String"),
            @ApiImplicitParam(name = "status", value="订单状态,1未付款，2已付款，3物流中，4订单完成",required = true,paramType = "String")
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO getGoodsOrderByStatus(@RequestParam("userName")String userName,@RequestParam("status")String status){
        return orderService.getGoodsOrderByStatus(userName,status);
    }

    @ApiOperation("查找所有人员购买记录")
    @GetMapping("/getAllGoodsBuyRecords")
    @Transactional(rollbackFor = Exception.class)
    public ResultVO getAllGoodsBuyRecords(){
        return orderService.getAllGoodsBuyRecords();
    }

    @ApiOperation("根据用户名查找购买记录")
    @GetMapping("/getGoodsBuyRecordsByUserName")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value="用户名",required = true,paramType = "String"),
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO getGoodsBuyRecordsByUserName(@RequestParam("userName")String userName){
        return orderService.getGoodsBuyRecordsByUserName(userName);
    }

    @ApiOperation("根据用户名和订单编号删除购买记录")
    @GetMapping("/deleteGoodsBuyRecordsByUserNameAndBuyRecordId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value="用户名",required = true,paramType = "String"),
            @ApiImplicitParam(name = "id", value="订单编号",required = true,paramType = "Integer"),
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO deleteGoodsBuyRecordsByUserNameAndBuyRecordId(@RequestParam("userName")String userName,@RequestParam("id")Integer id){
        return orderService.deleteGoodsBuyRecordsByUserNameAndBuyRecordId(userName,id);
    }

    @ApiOperation("根据用户名和订单编号查找购买记录")
    @GetMapping("/getGoodsBuyRecordsByUserNameAndBuyRecordId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value="用户名",required = true,paramType = "String"),
            @ApiImplicitParam(name = "id", value="订单编号",required = true,paramType = "Integer"),
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO getGoodsBuyRecordsByUserNameAndBuyRecordId(@RequestParam("userName")String userName,@RequestParam("id")Integer id){
        return orderService.getGoodsBuyRecordsByUserNameAndBuyRecordId(userName,id);
    }

    @ApiOperation("更新订单状态")
    @GetMapping("/updateGoodsOrderById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value="订单编号",required = true,paramType = "Integer"),
            @ApiImplicitParam(name = "goodsStatus", value="订单状态",required = true,paramType = "String"),
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO updateGoodsOrderById(@RequestParam("id")Integer id,@RequestParam("goodsStatus")String goodsStatus){
        return orderService.updateGoodsOrderById(id,goodsStatus);
    }



    @ApiOperation("根据订单编号获取订单")
    @GetMapping("/getGoodsOrderById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value="订单编号",required = true,paramType = "Integer"),
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO getGoodsOrderById(@RequestParam("id")Integer id){
        return orderService.getGoodsOrderById(id);
    }


}
